package com.fanjia.taobao.user.service.impl;

import com.fanjia.taobao.common.exceptionhandler.MyException;
import com.fanjia.taobao.log.aop.Log;
import com.fanjia.taobao.user.dao.UserDao;
import com.fanjia.taobao.user.entity.User;
import com.fanjia.taobao.user.service.UserService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 用户信息表(User)表服务实现类
 *
 * @author fanjia
 * @since 2021-04-07 17:08:20
 */
@Service("userService")
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;


    /**
     * 新增数据
     *
     * @param user 实例对象
     * @return 实例对象
     */
    @Override
    @Log("新增用户")
    public User insert(User user) {
        this.userDao.insert(user);
        return user;
    }



    @Override
    public User queryByUsername(String username) {
        return userDao.queryByUsername(username);
    }

    @Override
    @Log("更新用户")
    public int update(User user) {
        return userDao.update(user);
    }

    @Override
    @Log("删除用户")
    public int delete(int id) {
        return userDao.delete(id);
    }

    @Override
    //@Log("查询用户")
    public List<User> query(User user,int pageNum,int pageSize) {

        PageHelper.startPage(pageNum, pageSize);
        return userDao.query(user);
    }

    @Override
    public int queryCount(User user) {
        List<User> userList = userDao.query(user);
        return userList.size();
    }


}